package com.hrzyit.whistle.cases.presenter

import com.hrzyit.base.ext.execute
import com.hrzyit.base.presenter.BasePresenter
import com.hrzyit.base.rx.BaseObserver
import com.hrzyit.whistle.cases.data.bean.CaseIndexUserInfoVo
import com.hrzyit.whistle.cases.presenter.view.SelectDeptUserView
import com.hrzyit.whistle.cases.service.ICaseCenterService
import javax.inject.Inject

/**
 * 案件派遣人选择 Presenter
 * @author YangWei
 * @date 2019/4/20
 */
class SelectDeptUserPresenter @Inject constructor() : BasePresenter<SelectDeptUserView>() {

    @Inject
    lateinit var caseCenterService: ICaseCenterService


    /**
     * 获取案件派遣人信息列表
     * @author YangWei
     * @date 2019/4/19
     * @param caseId   案件id
     * @param userId   操作人id
     * @return 案件派遣人信息列表 @{link CaseIndexUserInfoVo}
     */
    fun selectCaseDispatchUserList(caseId: Long, userId: Long) {
        if (!checkNetWork()) {
            return
        }

        // 显示进度框
        mView.showLoading()

        caseCenterService.selectCaseDispatchUserList(caseId, userId)
            .execute(object : BaseObserver<MutableList<CaseIndexUserInfoVo>>(mView) {
                override fun onNext(t: MutableList<CaseIndexUserInfoVo>) {
                    mView.onGetSelectCaseDispatchUserListSuccess(t)
                }
            }, lifecycleProvider)
    }

    /**
     * 保存案件派遣人(处置人)信息
     * @author YangWei
     * @date 2019/4/20
     * @param caseId   案件id
     * @param userId   操作人id
     * @param disposeDeptId   处置单位id
     * @param disposeUserId   处置人id
     * @return 成功(true)|失败(false)
     */
    fun saveCaseDisposeUser(caseId: Long, userId: Long, disposeDeptId: Long, disposeUserId: Long) {
        if (!checkNetWork()) {
            return
        }

        // 显示进度框
        mView.showLoading()

        caseCenterService.saveCaseDisposeUser(caseId, userId, disposeDeptId, disposeUserId)
            .execute(object : BaseObserver<Boolean>(mView) {
                override fun onNext(t: Boolean) {
                    mView.onSaveCaseDisposeUserSuccess(t)
                }
            }, lifecycleProvider)
    }

}